package mspbots.next.ticket.core.points;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * mspbots.next.ticket.core.points.PointTicketRegistry
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/11/30
 */
@Service
public class PointTicketRegistry {

    private final List<PointTicketRegistration> registrations;

    public PointTicketRegistry() {
        this.registrations = new ArrayList<>();
    }

    public PointTicketRegistry addPointTicket(PointTicketRegistration pointTicketRegistration) {
        this.registrations.add(pointTicketRegistration);
        return this;
    }

    /**
     * Return sorted PointTicket registration.
     */
    public List<PointTicketRegistration> getPointTickets() {
        return this.registrations.parallelStream()
                .sorted(Comparator.comparing(PointTicketRegistration::getPoint).reversed())
                .collect(Collectors.toList());
    }
}
